package com.hxzy.demo.Adapter0926;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hxzy.demo.R;

import java.util.List;

/**
 * Created by Yang on 2016/9/26.
 */
public class ContactAdapter extends BaseAdapter{
    private List<ContactEntity> contactEntityList;

    public ContactAdapter(List<ContactEntity> contactEntityList){
        this.contactEntityList = contactEntityList;
    }
    @Override
    public int getCount() {
        return contactEntityList.size();
    }

    @Override
    public ContactEntity getItem(int position) {
        return contactEntityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View itemView = View.inflate(parent.getContext(), R.layout.item_test_list_view,null);
        TextView contactNameTV = (TextView) itemView.findViewById(R.id.contact_name);
        TextView contactCharTV = (TextView) itemView.findViewById(R.id.contact_char);
        ImageView contactAvatar = (ImageView) itemView.findViewById(R.id.avatar);

        ContactEntity contactEntity = getItem(position);
        contactNameTV.setText(contactEntity.name);
        contactCharTV.setText(contactEntity.nameChar);
        contactAvatar.setImageResource(contactEntity.avatarResId);
        return itemView;
    }
}
